package demo.k8s;
import com.alibaba.fastjson2.JSON;
import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.openapi.ApiException;
import io.kubernetes.client.openapi.Configuration;
import io.kubernetes.client.openapi.apis.CoreV1Api;
import io.kubernetes.client.openapi.apis.CustomObjectsApi;
import io.kubernetes.client.openapi.models.V1NamespaceList;
import io.kubernetes.client.openapi.models.V1Pod;
import io.kubernetes.client.openapi.models.V1PodList;
import io.kubernetes.client.util.ClientBuilder;
import io.kubernetes.client.util.Config;
import io.kubernetes.client.util.credentials.AccessTokenAuthentication;

import java.io.IOException;
public class KubernetesClientDemo {


    public static void main(String[] args) throws IOException, ApiException{
        ApiClient client = Config.defaultClient();
        Configuration.setDefaultApiClient(client);

        CoreV1Api api = new CoreV1Api();
//        V1PodList list = api.listPodForAllNamespaces(null, null, null, null, null, null, null, null, null);
//        for (V1Pod item : list.getItems()) {
//            System.out.println(item.getMetadata().getName());
//        }
    }

    /**
     * ApiClient初始化&认证
     */
    public void testInitClient(){
        ApiClient client = new ClientBuilder()
                .setBasePath("ApiServer地址")
                .setVerifyingSsl(false)
                .setAuthentication(new AccessTokenAuthentication("Token")).build();
        Configuration.setDefaultApiClient(client);
        // CRD资源增删改查
        CustomObjectsApi apiInstance = new CustomObjectsApi();

        // Namespaces增删改查
        CoreV1Api coreV1Api = new CoreV1Api();

    }


}
